﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Demo
{

    public partial class Form1 : Form
    {
        public static int touxiang=0;
        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)//头像更换
        {
            touxiang =(touxiang+1)%3;
            if (touxiang == 0)
            {
                pictureBox1.Image = Properties.Resources._1653958523539_jpg;
            }
            if(touxiang==1)
            {
                pictureBox1.Image = Properties.Resources._1x图片_Copy_3;
            }
            if (touxiang == 2)
            {
                pictureBox1.Image = Properties.Resources._1x群组;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)//头像移动
        {
            if (pictureBox1.Location.X < 140)
            {
                pictureBox1.Location = new Point(pictureBox1.Location.X + 2, pictureBox1.Location.Y +1 );
            }
            else {
                string str = comboBox1.Text;
                Form2 form2=new Form2(str);
                form2.Show();
                this.Hide();
                timer1.Stop();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)//登录成功动画!事件
        {
            Random rand = new Random();
            int i = rand.Next();
            i = i % 6;
            switch(i){
                case 0:
                case 1:
                        label4.ForeColor = Color.Red;
                        break;
                case 2:
                case 3:
                        label4.ForeColor = Color.Black;
                        break;
                case 4:
                case 5:
                        label4.ForeColor = Color.Brown;
                        break;

            }
        }
        //判断登录
        private bool login()
        { 
         if(textBox1.Text==""||textBox2.Text==""||comboBox1.Text=="")
         {
             MessageBox.Show("请输入完整信息！朋友", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return false;
         }


         if (comboBox1.Text == "学生")
         { string sql = "select * from student where name='" + textBox1.Text+  "' and password='" + textBox2.Text + "'";
         fengzhuang dao = new fengzhuang();
         IDataReader dr = dao.read(sql);
         if (dr.Read()) { return true; }
         else { MessageBox.Show("输入信息有误！伙计", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; }
         }


         if (comboBox1.Text == "教师")
         {
             string sql = "select * from teacher where name='" + textBox1.Text + "' and password='" + textBox2.Text + "'";
          fengzhuang dao = new fengzhuang();
         IDataReader dr = dao.read(sql);
         if (dr.Read()) { return true; }
         else { MessageBox.Show("输入信息有误！年轻人", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; }
         }

         return false;
        }
        private void button1_Click(object sender, EventArgs e)//点击登录事件
        {
            if (login())
            {
                timer1.Start();
                timer2.Start();
                textBox1.Visible = false;
                textBox2.Visible = false;
                comboBox1.Visible = false;
                label1.Visible = false;
                label2.Visible = false;
                label3.Visible = false;
                button1.Visible = false;
                button2.Visible = false;
                label4.Visible = true;
                pictureBox1.Enabled = false;
                startProgress();
            }

        }

        private void button2_Click(object sender, EventArgs e)//点击重置事件
        {
            textBox1.Text = null;
            textBox2.Text = null;
            comboBox1.Text = null;
        }
        //滚动条
        private void startProgress()
        {
            // 显示进度条控件.
            pBar1.Visible = true;
            // 设置进度条最小值.
            pBar1.Minimum = 1;
            // 设置进度条最大值.
            pBar1.Maximum = 15;
            // 设置进度条初始值
            pBar1.Value = 1;
            // 设置每次增加的步长
            pBar1.Step = 1;

            // 循环执行
            for (int x = 1; x <= 15; x++)
            {
                // 每次循环让程序休眠300毫秒
                System.Threading.Thread.Sleep(200);
                // 执行PerformStep()函数
                pBar1.PerformStep();
            }
            pBar1.Visible = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }









    }
}
